package com.gxuwz.Market.business.action.web;

import java.io.PrintWriter;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.google.gson.Gson;
import com.gxuwz.Market.business.entity.ServiceAcademy;
import com.gxuwz.Market.business.entity.ServiceClass;
import com.gxuwz.Market.business.entity.ServiceMajor;
import com.gxuwz.Market.business.entity.ServiceStudio;
import com.gxuwz.Market.business.entity.SysUser;
import com.gxuwz.Market.business.service.IServiceAcademyService;
import com.gxuwz.Market.business.service.IServiceClassService;
import com.gxuwz.Market.business.service.IServiceDataService;
import com.gxuwz.Market.business.service.IServiceMajorService;
import com.gxuwz.Market.business.service.IServiceStudioService;
import com.gxuwz.Market.business.service.IServiceTaskService;
import com.gxuwz.Market.business.service.ISysUserService;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import util.MailUtil;

public class DataJsonAction extends BaseAction implements Preparable, ModelDriven<SysUser> {
	
	protected static final String AllUser_JSP = "/WEB-INF/page/web/SysUser_allUsers.jsp";
	protected static final String ADD_JSP = "/WEB-INF/page/web/SysUser_add.jsp";
	
	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		
	}
	

	@Autowired
	private IServiceAcademyService serviceAcademyService;
	@Autowired
	private IServiceMajorService serviceMajorService;
	@Autowired
	private IServiceClassService serviceClassService;
	@Autowired
	private ISysUserService sysUserService;
	@Autowired
	private IServiceStudioService serviceStudioService;
	@Autowired
	private IServiceDataService serviceDataService;
	
	private SysUser sysUser;
	private String query;//异步查找关键字
	private String AcaVar;
	private String MajVar;
	private String ClaVar;
	private ServiceAcademy academy;//院系实体
	private  ServiceMajor Major;//专业实体
	private ServiceClass cla;//班级实体
	private ServiceStudio studio;//科室实体
	private List<SysUser> SysUserList;//用户列表
	
	
	public ServiceClass getCla() {
		return cla;
	}

	public void setCla(ServiceClass cla) {
		this.cla = cla;
	}

	public String sendMail(){
		query = query.substring(0,query.length() - 2);
		String emails = serviceDataService.sendMail(query);
		MailUtil.sendMail(emails);
		return null;
	}
	
	/**
	 * 查找所有学院列表
	 * @author 黄灵燕
	 * @date 2018-1-19
	 * @return
	 */
	public String FindAllAcademy(){
		List<ServiceAcademy> list = serviceAcademyService.findAll();
		Gson gson = new Gson();
		PrintWriter writer = getPrintWriter();
		writer.write(gson.toJson(list).toString());
		writer.flush();
		writer.close();
		return null;
	}

	/**
	 * 查找已选学院列表的专业
	 * @return
	 */
	public String FindAllMajorByAcademy(){
		List<ServiceMajor> list = serviceMajorService.findAllMajorByAcademy(query);
		Gson gson = new Gson();
		PrintWriter writer = getPrintWriter();
		writer.write(gson.toJson(list).toString());
		writer.flush();
		writer.close();
		return null;
	}
	/**
	 * 查找已选专业的班级列表
	 * @return
	 */
	public String FindAllClassByMajor(){
		List<ServiceClass> list = serviceClassService.findAllClassByMajor(query);
		Gson gson = new Gson();
		PrintWriter writer = getPrintWriter();
		writer.write(gson.toJson(list).toString());
		writer.flush();
		writer.close();
		return null;
	}
	
	/**
	 * 异步查找所有科室列表
	 * @return
	 */
	public String findAllStudio(){
		List<ServiceStudio>	 list = serviceStudioService.findAll();
		Gson gson = new Gson();
		PrintWriter writer = getPrintWriter();
		writer.write(gson.toJson(list).toString());
		writer.flush();
		writer.close();
		return null;
	}
	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getAcaVar() {
		return AcaVar;
	}

	public void setAcaVar(String acaVar) {
		AcaVar = acaVar;
	}

	public String getMajVar() {
		return MajVar;
	}

	public void setMajVar(String majVar) {
		MajVar = majVar;
	}

	public String getClaVar() {
		return ClaVar;
	}

	public void setClaVar(String claVar) {
		ClaVar = claVar;
	}

	public SysUser getSysUser() {
		return sysUser;
	}

	public void setSysUser(SysUser sysUser) {
		this.sysUser = sysUser;
	}

	public ServiceAcademy getAcademy() {
		return academy;
	}

	public void setAcademy(ServiceAcademy academy) {
		this.academy = academy;
	}

	public ServiceMajor getMajor() {
		return Major;
	}

	public void setMajor(ServiceMajor major) {
		Major = major;
	}

	public List<SysUser> getSysUserList() {
		return SysUserList;
	}

	public void setSysUserList(List<SysUser> sysUserList) {
		SysUserList = sysUserList;
	}

	@Override
	public SysUser getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	public ServiceStudio getStudio() {
		return studio;
	}

	public void setStudio(ServiceStudio studio) {
		this.studio = studio;
	}

	

}
